#include <iostream>
#include <string>
#include <unordered_map>
#include <memory>
#include <ctime>
#include <cstdlib>
#include <unistd.h>


class Session
{
public:
    Session(const std::string &username, const std::string &status) : _username(username), _status(status)
    {
        _crreate_time = time(nullptr);
    }

private: // 用户的基本信息
    std::string _username;
    std::string _status;
    uint64_t _crreate_time;
};

using session_ptr = std::shared_ptr<Session>;

class SessionManager
{
public:
    SessionManager()
    {
        srand(time(nullptr) ^ getpid());
    }
    std::string AddSession(session_ptr s)
    {
        uint32_t randomid = rand() + time(nullptr);
        std::string sessionid = std::to_string(randomid);
        _sessions[sessionid] = s;
        return sessionid;
    }
    session_ptr GetSession(const std::string &sessionid)
    {
        if(_sessions.find(sessionid) != _sessions.end())
        {
            return _sessions[sessionid];
        }
        return nullptr;
    }
private:
    std::unordered_map<std::string, session_ptr> _sessions; // 通过sessionid来找到对应的session
};